

import java.math.BigDecimal;
import java.math.MathContext;



/**
 * @author navas
 *
 */
public class PlusBinExpr extends BinExpr {

	public PlusBinExpr(Expr leftExpr, Expr rightExpr) {
		super(leftExpr, rightExpr);

	}

	@Override
	public BigDecimal evaluate(Env env) {

		BigDecimal value = leftExpr.evaluate(env).add(rightExpr.evaluate(env), MathContext.DECIMAL128);

		return value;


	}

	public static PlusBinExpr _(Expr leftExpr, Expr rightExpr) {
		return new PlusBinExpr(leftExpr, rightExpr);
	}

	public String toString(){
		String leftExprTmp = leftExpr.toString();
		String rightExprTmp = "("+rightExpr.toString()+")";

		if(leftExpr.isAssignExpr())
			leftExprTmp = "("+leftExprTmp+")";
		if(rightExpr.isUnExpr() || rightExpr.isNum() || rightExpr.isId() || rightExpr.isTimesBinExpr() || rightExpr.isDivideBinExpr())
			rightExprTmp = rightExpr.toString();

		return leftExprTmp+" + "+rightExprTmp;
	}

	@Override
	public boolean isUnExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isAssignExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isPlusBinExpr() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isMinusBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isTimesBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isDivideBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean isNum() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isId() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isSeqExpr() {
		// TODO Auto-generated method stub
		return false;
	}
}
